import { defineStore } from 'pinia';
import { getSiteConfig } from '@/api/config';

export const useConfigStore = defineStore('config', {
  state: () => ({ siteConfig: [] }),

  getters: {
    configs: (state) => {
      return state.siteConfig;
    }
  },

  actions: {
    async initSiteConfig() {
      this.siteConfig = (await getSiteConfig())?.data ?? []
    },
    findValue(key) {
      return this.siteConfig.find(item => item['key'] === key)?.value ?? '';
    },
    cleanData() {
      this.$reset()
    }
  },
});
